package com.yunfeng.web;

import com.yunfeng.web.test.ReceiveAlicomMsgDemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableScheduling //定时任务
@EnableSwagger2
@Configuration
public class SpringBootJpaMySqlApplication extends SpringBootServletInitializer {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String helloWorld() {
        return "Hello World";
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringBootJpaMySqlApplication.class, args);
    }

    /**
     * 添加摘要信息(Docket)  http://localhost:8080/swagger-ui.html#/
     */
    @Bean
    public Docket controllerApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("云丰网络科技接口文档")
                        .description("房源，员工管理")
                        .contact(new Contact("南辕北辙", null, null))
                        .version("版本号:1.0")
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yunfeng.web.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        //开启短信监听渠道
//        ReceiveAlicomMsgDemo.onReceiveListener();
        // 注意这里要指向原先用main方法执行的Application启动类
        return builder.sources(SpringBootJpaMySqlApplication.class);
    }

}
